package cc.mrbird.statistical.service.impl;

import cc.mrbird.assets.dao.AssetManaMapper;
import cc.mrbird.assets.domain.AssetMana;
import cc.mrbird.assets.domain.AssetType;
import cc.mrbird.common.service.impl.BaseService;
import cc.mrbird.statistical.domain.EquipmentAnalysis;
import cc.mrbird.statistical.service.EquipmentAnalysisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service("equipmentAnalysisService")
public class EquipmentAnalysisServiceImpl extends BaseService<EquipmentAnalysis> implements EquipmentAnalysisService {

    @Autowired
    private AssetManaMapper assetManaMapper;
    //故障率统计 = 所有未正常的设备/所有设备
    @Override
    public Map<String, Float> failureRateStatistics(String nextTime) {
        Map<String,Float> failureRateStatisticMap = new HashMap<>();
        List<AssetType> totalType = assetManaMapper.findTotalType();
      /*  List<AssetType> assetTypeList = assetManaMapper.findAllType();*/
        float failureRate = 0;
        if(!totalType.isEmpty()){
            for (int i = 0; i < totalType.size(); i++) {
                String asset_type_name = totalType.get(i).getAsset_type_name();
                Integer failureRateByType = assetManaMapper.findFailureRateByType(asset_type_name, nextTime);
                Integer AllByType = assetManaMapper.findAllByType(asset_type_name, nextTime);
                failureRate = (float)failureRateByType / AllByType;
                failureRateStatisticMap.put(asset_type_name,failureRate);
            }
            return failureRateStatisticMap;
        }
        return null;
    }
}
